package com.boot.controller;

import com.boot.entity.Notify;
import com.boot.service.INotifyManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.rmi.runtime.Log;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ApplicationController {

    public final INotifyManagementService service;

    @Autowired
    public ApplicationController(INotifyManagementService service) {
        this.service = service;
    }

    @RequestMapping("/")
    public String app(Model model) {
        List<Notify> notifies = service.queryAllNotify(1);
        model.addAttribute("notifies", notifies);
        return "index";
    }

    @RequestMapping("/toggle")
    @ResponseBody
    public String moon(String cls, HttpSession session) {
        System.out.println(cls);
        if ("dark".equals(cls)) {
            session.setAttribute("dark", cls);
            session.setMaxInactiveInterval(24 * 60 * 60);
        } else {
            session.removeAttribute("dark");
        }
        return "ok";
    }
}
